package com.usabb.service.impl;

import com.ifast.common.base.CoreServiceImpl;
import com.usabb.api.dto.HospitalDTO;
import com.usabb.dao.HospitalDao;
import com.usabb.domain.HospitalDO;
import com.usabb.enums.BizTypeEnum;
import com.usabb.service.HospitalRelationService;
import com.usabb.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <pre>
 * 医院表
 * </pre>
 * <small> 2019-09-24 10:08:40 | Jory</small>
 */
@Service
public class HospitalServiceImpl extends CoreServiceImpl<HospitalDao, HospitalDO> implements HospitalService {
    @Autowired
    private HospitalRelationService hospitalRelationService;

    @Override
    public List<HospitalDO> getByBizTypeAndBizId(BizTypeEnum bizTypeEnum, Long bizId) {
        List<Long> hospitalIds = hospitalRelationService.getHospitalIdsBy(bizTypeEnum.name(), bizId);
        return CollectionUtils.isEmpty(hospitalIds) ? new ArrayList<>() : this.selectBatchIds(hospitalIds);
    }

    @Override
    public List<HospitalDTO> getDTOListByBizTypeAndBizId(BizTypeEnum bizTypeEnum, Long bizId) {
        final List<HospitalDO> hospitalDOS = getByBizTypeAndBizId(bizTypeEnum, bizId);

        return CollectionUtils.isEmpty(hospitalDOS)
                ? new ArrayList<>()
                : hospitalDOS.stream().map(it -> HospitalDTO.of(it)).collect(Collectors.toList());

    }
}
